package org.feng;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.feng.common.util.SpringContextUtil;
import org.feng.handler.RoleDataPermissionHandler;
import org.feng.handler.SimpleDataPermissionHandler;
import org.feng.interceptor.MybatisPlusPermissionInterceptor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 启动类
 *
 * @author Administrator
 */
@Slf4j
@SpringBootApplication
public class StartApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
       appendMybatisPlusInnerInterceptor();
    }

    private void appendMybatisPlusInnerInterceptor() {
        log.info("追加Mybatis-plus拦截器");
        MybatisPlusInterceptor mybatisPlusInterceptor = SpringContextUtil.getBean(MybatisPlusInterceptor.class);
        mybatisPlusInterceptor.addInnerInterceptor(new MybatisPlusPermissionInterceptor(new RoleDataPermissionHandler()));
    }
}
